package cn.pugle.oj.leetcode;

import cn.pugle.oj.catalog.GraphProblem;

import java.util.*;

/**
 * 错误写法
 * https://leetcode.com/problems/redundant-connection/description/
 *
 * @author tzp
 * @since 2020/11/2
 */
public class LC684 implements GraphProblem {
    public int[] findRedundantConnection(int[][] edges) {
        //环detect
        HashSet<Integer> set = new HashSet<>();
        for (int[] edge : edges) {
            if (set.contains(edge[0]) && set.contains(edge[1])) {
                return edge;
            } else {
                set.add(edge[0]);
                set.add(edge[1]);
            }
        }
        return null;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new LC684()
//                .findRedundantConnection(new int[][]{{1, 2}, {1, 3}, {2, 3}})));
//                .findRedundantConnection(new int[][]{{1, 2}, {2, 3}, {3, 4}, {1, 4}, {1, 5}})));
                .findRedundantConnection(new int[][]{{3, 4}, {1, 2}, {2, 4}, {3, 5}, {2, 5}})));
        //34, 12分别来, 再来24, 以为有环了?, 所以不能放到一个set里,
        //放到多个set里, 就是分组了, 就是并查集的思想了
    }
}
